home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap08 / howto05 / delphi10 / uniqkey / unikey.sql < prev    next >
Encoding:
Text File  |  1996-04-14  |  1.2 KB  |  66 lines

  1. connect "C:\DDS\CHAP08\CSHOWTO.GDB"
  2. user "SYSDBA" password "masterkey";
  3.  
  4.  
  5. /*****************************************************************
  6.   Create sample table
  7. */
  8.  
  9. Create Table BookTable
  10. (
  11.   BookId                 smallint not null,
  12.   Title                  varchar( 30 ),
  13.   Authors                varchar( 30 ),
  14.   Primary Key( BookId )
  15. );
  16.  
  17. COMMIT;
  18.  
  19. /*****************************************************************
  20.   Create key generator for sample table
  21. */
  22.  
  23. Create Generator BookGenerator;
  24. Set Generator BookGenerator to 0;
  25.  
  26. COMMIT;
  27.  
  28. /*****************************************************************
  29.   Create stored procedure for sample table
  30. */
  31.  
  32. Set Term ! ;
  33.  
  34. Create Procedure NewBookIdProcedure
  35.   Returns ( TheNewBookId Integer )
  36.   As
  37. begin
  38.   TheNewBookId = Gen_Id( BookGenerator, 1 );
  39. end !
  40.  
  41. Set Term ; !
  42.  
  43. COMMIT;
  44.  
  45. /*****************************************************************
  46.   Create trigger for sample table
  47. */
  48.  
  49. Set Term ! ;
  50.  
  51. Create Trigger BookTableBerforeInsert
  52.   For BookTable
  53.   Before Insert
  54.   As
  55. begin
  56.   if ( New.BookId is Null ) then
  57.   begin
  58.     Execute procedure NewBookIdProcedure
  59.       Returning_Values New.BookId;
  60.   end
  61. end !
  62.  
  63. Set Term ; !
  64.  
  65. COMMIT;
  66.